package com.ruoyi.teaching.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.RepetitiveManagement;
import com.ruoyi.teaching.domain.TaskHistory;
import com.ruoyi.teaching.domain.dto.ActivityDto;
import com.ruoyi.teaching.domain.dto.TaskDto;
import com.ruoyi.teaching.service.IRepetitiveManagementService;
import com.ruoyi.teaching.service.ITaskHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 留级管理Controller
 * 
 * @author thl
 * @date 2024-01-05
 */
@RestController
@RequestMapping("/repetitiveManagement")
public class RepetitiveManagementController extends BaseController
{
    @Autowired
    private IRepetitiveManagementService repetitiveManagementService;
    @Autowired
    private ITaskHistoryService taskHistoryService;

    /**
     * 编辑任务的新增 保存
     * @param
     * @return
     */
    @PostMapping("/activity")
    private AjaxResult activity(@RequestBody ActivityDto activityDto){
       List<TaskHistory> taskHistories = taskHistoryService.selectActivityList(activityDto);
        return AjaxResult.success(taskHistories);


    }
    @PostMapping("/editTask")
    public AjaxResult editTask(@RequestBody TaskDto taskDto){
        return repetitiveManagementService.editTask(taskDto);

    }
    /**
     * 查询留级管理列表
     */
    @RequiresPermissions("teaching:repetitiveManagement:list")
    @GetMapping("/list")
    public TableDataInfo list(RepetitiveManagement repetitiveManagement)
    {
        startPage();
        List<RepetitiveManagement> list = repetitiveManagementService.selectRepetitiveManagementList(repetitiveManagement);
        return getDataTable(list);
    }

    /**
     * 导出留级管理列表
     */
    @RequiresPermissions("teaching:repetitiveManagement:export")
    @Log(title = "留级管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepetitiveManagement repetitiveManagement)
    {
        List<RepetitiveManagement> list = repetitiveManagementService.selectRepetitiveManagementList(repetitiveManagement);
        ExcelUtil<RepetitiveManagement> util = new ExcelUtil<RepetitiveManagement>(RepetitiveManagement.class);
        util.exportExcel(response, list, "留级管理数据");
    }

    /**
     * 获取留级管理详细信息
     */
    @RequiresPermissions("teaching:repetitiveManagement:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(repetitiveManagementService.selectRepetitiveManagementById(id));
    }

    /**
     * 新增留级管理
     */
    @RequiresPermissions("teaching:repetitiveManagement:add")
    @Log(title = "留级管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepetitiveManagement repetitiveManagement)
    {
        return toAjax(repetitiveManagementService.insertRepetitiveManagement(repetitiveManagement));
    }

    /**
     * 修改留级管理
     */
    @RequiresPermissions("teaching:repetitiveManagement:edit")
    @Log(title = "留级管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepetitiveManagement repetitiveManagement)
    {
        return toAjax(repetitiveManagementService.updateRepetitiveManagement(repetitiveManagement));
    }

    /**
     * 删除留级管理
     */
    @RequiresPermissions("teaching:repetitiveManagement:remove")
    @Log(title = "留级管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(repetitiveManagementService.deleteRepetitiveManagementByIds(ids));
    }
}
